<template>
  <view class="order-detail">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
		<view class="back-btn" @click="backPage()">
			<image style="width: 40px;height: 30px;" src="/static/left.png"></image>
		</view>
		<view class="title">订单详情</view>
    </view>
    
    <!-- 订单内容区域 -->
    <view class="order-content">
      <!-- 核销码信息 -->
      <view class="verification-code">
        <view class="code">核销码 {{orderInfo.verificationCode}}</view>
		<view class="car">车辆：奔驰FWE4/豫A98FHJ</view>
      </view>
      
      <!-- 服务内容 -->
      <view class="service-content">
        <view class="section-title">服务内容</view>
        <view class="service-item">
          <text>{{orderInfo.serviceName}}</text>
          <text>¥{{orderInfo.serviceOriginalPrice}}</text>
          </view>
		  <view class="service-item">
			  <text>车辆附加费用</text>
			  <text></text>
		  </view>
      </view>
      
      <!-- 订单信息 -->
      <view class="order-info">
        <view class="section-title">订单信息</view>
        <view class="info-item">
          <text>原价</text>
          <text>¥{{orderInfo.serviceOriginalPrice}}</text>
        </view>
        <view class="info-item" >
          <text>优惠</text>
          <text style="color: red;">-¥{{(orderInfo.serviceOriginalPrice-orderInfo.serviceCurrentPrice).toFixed(2)}}</text>
        </view>
        <view class="info-item" >
          <text>实付金额</text>
          <text style="color: red;">¥{{orderInfo.serviceCurrentPrice}}</text>
        </view>
        <view class="info-item">
          <text>订单编号</text>
          <text>{{orderInfo.orderNum}}</text>
        </view>
        <view class="info-item">
          <text>预约时间</text>
          <text>{{orderInfo.reservationTime}}</text>
        </view>
        <view class="info-item">
          <text>支付时间</text>
          <text>{{orderInfo.orderTime}}</text>
        </view>
        <view class="info-item">
          <text>核销时间</text>
          <text>{{orderInfo.verificationTime}}</text>
        </view>
      </view>
    </view>
    
    <!-- 底部按钮 -->
    <view class="bottom-button" :class="{'disabled': orderInfo.isVerified}" @tap="handleVerification">
      {{orderInfo.isVerified ? '已核销' : '确认核销'}}
    </view>
  </view>
</template>

<script>
import request from '/utils/request.js';
export default {
  data() {
    return {
      orderInfo:[],
      carInfo:[],
      brandInfo:[],
      typeInfo:[],
	  serviceInfo:[],
    }
  },
  onLoad(options) {
  	if(options.id){
		console.log(options,"我去额企鹅")
		this.enterOrderDetail(options.id);
		this.enterService(options.id)
	}
  },
  methods: {
    backPage() {
      uni.navigateBack({
        delta: 2
      })
    },
	enterOrderDetail(id){
		request({
			url:`/offer/orders/${id}`,
			method:'GET',
      header:{
        Authorization:uni.getStorageSync('token')
      },
			success:(res)=>{
				if(res.data.code===200){
					this.orderInfo=res.data.data
          if(this.orderInfo.serviceId){
            this.enterService(this.orderInfo.serviceId)
          }
				}
				console.log(this.orderInfo)
			}
		})
	},
	enterService(id){
		request({
			url:`/evaluate/details/${id}`,
			method:'GET',
			header:{
				Authorization:uni.getStorageInfoSync('token')
			},
			success:(res)=>{
				if(res.data.code===200){
					this.serviceInfo=res.data.data
          this.orderInfo.serviceName=this.serviceInfo.serviceName,
          this.orderInfo.serviceCurrentPrice=this.serviceInfo.serviceCurrentPrice
		  this.orderInfo.serviceOriginalPrice=this.serviceInfo.serviceOriginalPrice
				}
				console.log(this.orderInfo.serviceName)
			}
		})
	},
	
    handleVerification() {
      if (this.orderInfo.isVerified) return
      
      uni.showModal({
        title: '核销此订单',
        content: '请您仔细核对订单，此操作不可撤销\n请谨慎操作！',
        cancelText: '取消',
        confirmText: '确认',
        success: (res) => {
          if (res.confirm) {
            // 这里添加核销的接口调用
            this.orderInfo.isVerified = true
            this.orderInfo.verificationTime = new Date().toLocaleString()
          }
        }
      })
    }
  }
}
</script>

<style lang="scss">
.order-detail {
  min-height: 100vh;
  background-color: #f5f5f5;
  
  .nav-bar {
    background-color: #007AFF;
    color: #fff;
    padding: 15px 10px;
    display: flex;
	text-align: center;
    .title {
      flex: 1;
      text-align: center;
      font-size: 18px;
    }
  }
  
  .order-content {
    padding: 16px;
    
    .verification-code {
      background-color: #fff;
      padding: 16px;
      border-radius: 8px;
      margin-bottom: 16px;
      
      .code {
        font-size: 18px;
        font-weight: bold;
        margin-bottom: 8px;
      }
      
      .car-info {
        color: #666;
      }
    }
    
    .section-title {
      font-size: 16px;
      margin-bottom: 12px;
	  font-weight: bolder;
    }
    
    .service-content, .order-info {
      background-color: #fff;
      padding: 16px;
      border-radius: 8px;
      margin-bottom: 16px;
    }
    
    .service-item, .info-item {
      display: flex;
      justify-content: space-between;
      margin-bottom: 12px;
      color: #333;
      
      &:last-child {
        margin-bottom: 0;
      }
    }
  }
  
  .bottom-button {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50px;
    background-color: #007AFF;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    
    &.disabled {
      background-color: #999;
    }
  }
}

.back-btn{ margin-left: 20rpx; width: 50rpx; height: 50rpx; position: relative;}	
.back-icon { width: 30px; height: 30px;}	
.back-icon::before { content: ""; position: absolute; width: 20px; height: 2px; background-color: #fff; top: 10rpx; left: 47rpx; transform: translate(-50%, -50%); }
.back-icon::after { content: ""; position: absolute; width: 10px; height: 10px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: rotate(45deg); top: 0rpx; left: 30rpx;}
</style>
